import { formatParams } from "@/utils/index";
import request from "@/utils/request";

/**
 * 创建空白稿件
 * @param {number} type 稿件类型
 */
export function createArchiveAPI(type) {
    return request({
        url: "/archive/base",
        method: "POST",
        data: { type },
    });
}
/**
 * 删除稿件
 * @param {稿件id} aid 稿件id
 */
export function delArchiveAPI(aid) {
    return request({
        url: `/archive/base/${aid}`,
        method: "DELETE",
    });
}
/**
 * 修改稿件(保存草稿)
 * @param {number} aid 稿件id
 * @param {Object}} archiveForm 修改的数据
 */
export function putArchiveAPI(aid, archiveForm) {
    const columns = ["cid", "cover", "title", "mark", "content"]; // 格式化条件
    const updateData = formatParams(archiveForm, columns);
    return request({
        url: `/archive/base/${aid}`,
        method: "PUT",
        data: updateData,
    });
}
/**
 * 获取稿件详情
 * @param {number} aid 稿件id
 */
export function getArchiveDetailAPI(aid) {
    return request({
        url: `/archive/base/${aid}`,
        method: "GET",
    });
}

export function getArchiveEditedAPI(type) {
    return request({
        url: "/archive/edited",
        method: "GET",
        params: { type },
    });
}

export function submitExamineAPI(aid) {
    return request({
        url: `/archive/submit/${aid}`,
        method: "PUT",
    });
}
/**
 * 获取稿件列表接口
 * @param {Object} param0 获取条件
 */
export function getArchiveListAPI({
    uid, type, state, page, size,
}) {
    return request({
        url: "/archives",
        method: "GET",
        params: {
            uid, type, state, page, size,
        },
    });
}

export function getArchiveExamineAPI({ type, page, size }) {
    return request({
        url: "/archives/examine",
        method: "GET",
        params: { type, page, size },
    });
}

export function archiveExamineAPI({
    type, aid, state, mark,
}) {
    return request({
        url: `/archive/examine/${aid}`,
        method: "PUT",
        data: { type, state, mark },
    });
}

export function getArchiveExamineLogAPI({
    type = 1, page = 1, size = 10, action,
}) {
    return request({
        url: `/archives/examine/log/${type}`,
        method: "GET",
        params: { page, size, action },
    });
}
/**
 *  添加稿件扩展信息接口
 * @param {number} aid 稿件id
 * @param {Object} param1 扩展键值对
 * @param {string} param1.key 扩展键
 * @param {string} param1.value 扩展值
 */
export function addArchiveMetaAPI(aid, { key, value }) {
    return request({
        url: "/archive/meta/add",
        method: "POST",
        data: { aid, key, value },
    });
}
/**
 * 删除稿件扩展信息接口
 * @param {number} aid 稿件id
 * @param {string}} key 扩展键
 */
export function delArchiveMetaAPI(aid, key) {
    return request({
        url: `/archive/meta/del/${aid}`,
        method: "DELETE",
        data: { key },
    });
}
/**
 *  修改稿件扩展信息接口
 * @param {number} aid 稿件id
 * @param {Object} param1 扩展键值对
 * @param {string} param1.key 扩展键
 * @param {string} param1.value 扩展值
 */
export function putArchiveMetaAPI(aid, { key, value }) {
    return request({
        url: `/archive/meta/update/${aid}`,
        method: "PUT",
        data: { key, value },
    });
}
/**
 * 按键获取稿件扩展信息接口
 * @param {number} aid 稿件id
 * @param {string}} key 扩展键
 */
export function getArchiveMetaAPI(aid, key) {
    return request({
        url: `/archive/metas/${aid}`,
        method: "GET",
        params: { key },
    });
}
/**
 *  获取稿件的图片附件
 * @param {number} aid 稿件id
 */
export function getArchiveImagesAPI(aid) {
    return request({
        url: `/archive/archive/images/${aid}`,
        method: "GET",
    });
}
